package com.job.structureType.agent.JDKProxy;



import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author 王博
 * @DateTime 2025-06-11 08:37
 */
public class ProxyFactory {
    public  StationTicketSeller station = new StationTicketSeller();
    public  TicketSeller getAgentTicketSeller() {
        return (TicketSeller)Proxy.newProxyInstance(
                station.getClass().getClassLoader(),
                station.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("通过代售点卖票");
                        Object result = method.invoke(station, args);
                        return result;
                    }
                });
    }
}
